package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import com.updateNew.MyIsif;
import org.come.entity.RoleSummoning;

import com.gl.util.Xy2Util;
import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.PetTujianSpecificBtn;
import com.tool.btn.SevenTwoChangesBtn;
import com.tool.btn.WorkshopBtn;
import com.tool.image.ImageMixDeal;
import com.tool.role.RoleData;
import com.tool.tcp.NewPart;
import com.tool.tcp.SpriteFactory;
import com.tool.tcpimg.UIUtils;
//召唤兽图鉴
public class PetTujianJpanel extends JPanel {
	private JLabel  labtext,labtext1,labtext2,labtext3,labtext4,tgmText;//
	private WorkshopBtn tuiguang,tuiguangSC;
	private static JTextField findName,findName1;
	private static String[] Fvalue;
	private static JTextArea testMes;// 用来显示聊天信息
	public String npczb;
	public static String npcfeiji;
	private NewPart[] part = new NewPart[5];
	private JLabel[] petName = new JLabel[5];
	private JLabel[] petnum = new JLabel[5];
	private String[] petids = new String[5];
	private JLabel[] sxtp = new JLabel[5];
	private int nowpage = 1;// 当前页数
	//
	private JLabel labpage; // 放置当前页数和总页数
	private PetTujianSpecificBtn
			selectBtn,
			btnhp,// 首页
			btnep,// 末页
			btnsyy,// 上一页
			btnxyy;// 下一页
	//合成
	private PetTujianSpecificBtn[] synthesis = new PetTujianSpecificBtn[5];
	private PetTujianSpecificBtn[] petdetails = new PetTujianSpecificBtn[5];
	private static JTextField labname;//模糊检索召唤兽名称
	public PetTujianJpanel() {

		this.setPreferredSize(new Dimension(682,404));
		this.setLayout(null);
		this.setBackground(UIUtils.Color_BACK);
		if ("水墨UI".equals(MyIsif.getStyle())) {
			// 关闭按钮事件
			FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/button/1.png", 1, 3013);
			offBtn.setBounds(682-23, 2, 23, 23);
			this.add(offBtn);
			// 放置当前页数和总页数
			labpage = new JLabel("", SwingConstants.CENTER);
			labpage.setForeground(Color.white);
			labpage.setBounds(330, 370, 58, 17);
			labpage.setFont(UIUtils.TEXT_FONT1);
			this.add(labpage);
			// 首页
			btnhp = new PetTujianSpecificBtn("inkImg/button/2.png", 1, "首页", 11, this,0);
			btnhp.setBounds(274, 370, 34, 17);
			this.add(btnhp);

			// 上一页
			btnsyy = new PetTujianSpecificBtn("inkImg/button/10.png", 1, "", 12, this,0);
			btnsyy.setBounds(310, 370, 19, 20);
			this.add(btnsyy);

			// 下一页
			btnxyy = new PetTujianSpecificBtn("inkImg/button/9.png", 1, "", 13, this,0);
			btnxyy.setBounds(392, 370, 19, 20);
			this.add(btnxyy);

			// 末页
			btnep = new PetTujianSpecificBtn("inkImg/button/2.png", 1, "末页", 14, this,0);
			btnep.setBounds(411, 370, 34, 17);
			this.add(btnep);

			for(int i=0;i<5;i++) {
				petName[i] = new JLabel();
				petName[i].setBounds(81, 353, 199, 15);
				petName[i].setForeground(Color.YELLOW);
				petName[i].setFont(new Font("楷体", Font.PLAIN, 14));
				this.add(petName[i]);
				petnum[i] = new JLabel();
				petnum[i].setBounds(81, 333, 99, 15);
				petnum[i].setForeground(Color.YELLOW);
				petnum[i].setFont(new Font("楷体", Font.PLAIN, 14));
				this.add(petnum[i]);
//				this.synthesis[i] = new PetTujianSpecificBtn("inkImg/button/2.png", 1, "合成", 16, this, i);
//				this.synthesis[i].setBounds(60, 333, 34, 17);
//				this.synthesis[i].setOpaque(false);
//				this.add(this.synthesis[i]);
				this.petdetails[i] = new PetTujianSpecificBtn("inkImg/button/2.png", 1, "详情", 17, this, i);
				this.petdetails[i].setBounds(60, 333, 34, 17);
				this.petdetails[i].setOpaque(false);
				this.add(this.petdetails[i]);

				sxtp[i] = new JLabel();
				sxtp[i].setVisible(false);
				this.add(sxtp[i]);
			}

			// 名称
			labname = new JTextField();
			labname.setBounds(516, 35, 99, 18);
			labname.setForeground(Color.white);
			labname.setOpaque(false);
			labname.setBorder(BorderFactory.createEmptyBorder());
			labname.setFont(UIUtils.TEXT_FONT1);
			labname.setCaretColor(Color.white);
			this.add(labname);
			this.selectBtn = new PetTujianSpecificBtn("inkImg/button/2.png", 1, "搜索", 15, this,0);
			this.selectBtn.setBounds(632, 34, 34, 17);
			this.selectBtn.setOpaque(false);
			this.add(this.selectBtn);
		} else {



			// 关闭按钮事件
			FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/hongmu/s74.png", 1, 3013);
			offBtn.setBounds(682-23, 2, 23, 23);
			this.add(offBtn);
			// 放置当前页数和总页数
			labpage = new JLabel("", SwingConstants.CENTER);
			labpage.setForeground(Color.white);
			labpage.setBounds(330, 370, 58, 17);
			labpage.setFont(UIUtils.TEXT_FONT1);
			this.add(labpage);
			// 首页
			btnhp = new PetTujianSpecificBtn("inkImg/hongmu/21_png.button.tab_nex.png", 1, "首页", 11, this,0);
			btnhp.setBounds(274, 370, 34, 17);
			this.add(btnhp);

			// 上一页
			btnsyy = new PetTujianSpecificBtn("img/xy2uiimg/29_png.button.btn_8.png", 1, "", 12, this,0);
			btnsyy.setBounds(310, 370, 19, 20);
			this.add(btnsyy);

			// 下一页
			btnxyy = new PetTujianSpecificBtn("img/xy2uiimg/36_png.button.btn_7.png", 1, "", 13, this,0);
			btnxyy.setBounds(392, 370, 19, 20);
			this.add(btnxyy);

			// 末页
			btnep = new PetTujianSpecificBtn("inkImg/hongmu/21_png.button.tab_nex.png", 1, "末页", 14, this,0);
			btnep.setBounds(411, 370, 34, 17);
			this.add(btnep);

			for(int i=0;i<5;i++) {
				petName[i] = new JLabel();
				petName[i].setBounds(81, 353, 199, 15);
				petName[i].setForeground(Color.YELLOW);
				petName[i].setFont(new Font("楷体", Font.PLAIN, 14));
				this.add(petName[i]);
				petnum[i] = new JLabel();
				petnum[i].setBounds(81, 333, 99, 15);
				petnum[i].setForeground(Color.YELLOW);
				petnum[i].setFont(new Font("楷体", Font.PLAIN, 14));
				this.add(petnum[i]);
//				this.synthesis[i] = new PetTujianSpecificBtn("inkImg/hongmu/21_png.button.tab_nex.png", 1, "合成", 16, this, i);
//				this.synthesis[i].setBounds(60, 333, 34, 17);
//				this.synthesis[i].setOpaque(false);
//				this.add(this.synthesis[i]);
				this.petdetails[i] = new PetTujianSpecificBtn("inkImg/hongmu/21_png.button.tab_nex.png", 1, "详情", 17, this, i);
				this.petdetails[i].setBounds(60, 333, 34, 17);
				this.petdetails[i].setOpaque(false);
				this.add(this.petdetails[i]);

				sxtp[i] = new JLabel();
				sxtp[i].setVisible(false);
				this.add(sxtp[i]);
			}

			// 名称
			labname = new JTextField();
			labname.setBounds(516, 35, 99, 18);
			labname.setForeground(Color.white);
			labname.setOpaque(false);
			labname.setBorder(BorderFactory.createEmptyBorder());
			labname.setFont(UIUtils.TEXT_FONT1);
			labname.setCaretColor(Color.white);
			this.add(labname);
			this.selectBtn = new PetTujianSpecificBtn("inkImg/hongmu/21_png.button.tab_nex.png", 1, "搜索", 15, this,0);
			this.selectBtn.setBounds(632, 34, 34, 17);
			this.selectBtn.setOpaque(false);
			this.add(this.selectBtn);
		}
		refresGoodsSplendid();
	}
	private ImageIcon icon,icon1;
	private ImageIcon icon2 = new ImageIcon("img/xy2uiimg/新上.png");

	@Override
	protected void paintComponent(Graphics g) {
		if ("水墨UI".equals(MyIsif.getStyle())) {
			super.paintComponent(g);
			ImageIcon image = new ImageIcon("inkImg/background/召唤兽图鉴.png");
			g.drawImage(image.getImage(), 0, 0, 682,404, this);
			// 绘制宝宝动态图
			for (int i = 0; i < 5; i++) {
				if(part[i]!=null) {
					part[i].draw(g, 90+i*115, 250, 0, ImageMixDeal.userimg.getTime());
					petName[i].setBounds(70+i*110, 350, 99, 15);
					petnum[i].setBounds(70+i*110, 330, 99, 15);
//					synthesis[i].setBounds(70+i*110, 300, 34, 17);
					petdetails[i].setBounds(104+i*110, 300, 34, 17);
				}
			}
		} else {
			super.paintComponent(g);
			ImageIcon image = new ImageIcon("img/xy2uiimg/召唤兽图鉴.png");
			g.drawImage(image.getImage(), 0, 0, 682,404, this);
			// 绘制宝宝动态图
			for (int i = 0; i < 5; i++) {
				if(part[i]!=null) {
					part[i].draw(g, 90+i*115, 250, 0, ImageMixDeal.userimg.getTime());
					petName[i].setBounds(70+i*110, 350, 99, 15);
					petnum[i].setBounds(70+i*110, 330, 99, 15);
//					synthesis[i].setBounds(70+i*110, 300, 34, 17);
					petdetails[i].setBounds(104+i*110, 300, 34, 17);
				}
			}
		}
		this.selectBtn.setBounds(632, 34, 34, 17);
	}


	/** 模糊检索 */
	public void selectPet() {
		String petName = labname.getText();
		List<RoleSummoning> petlist = Xy2Util.addpetList;
		if(petName!=null && petName!="") {
			List<RoleSummoning> petlist2 = new ArrayList<>();
			for(RoleSummoning petTujian:petlist) {
				if(petTujian.getSummoningname().contains(petName)) {
					petlist2.add(petTujian);
				}
			}
			if(petlist2.size()>0) {
				petlist = petlist2;
			}
		}
		nowpage = 1;
		// 刷新界面
		refreshDbgSplendid(petlist, nowpage);
	}




	/** 刷新PET */
	public void refresGoodsSplendid() {
		List<RoleSummoning> petlist = Xy2Util.addpetList;
		nowpage = 1;
		// 刷新界面
		refreshDbgSplendid(petlist, nowpage);
	}
	/**
	 * 重新展示图鉴界面
	 */
	public void refreshDbgSplendid(List<RoleSummoning> petlist , int nowpage) {
		part = new NewPart[5];
		for (int i = 0; i < 5; i++) {
			petName[i].setText("");
			petnum[i].setText("");
//			this.synthesis[i].setVisible(false);
			this.petdetails[i].setVisible(false);
			this.sxtp[i].setVisible(false);
		}
		int totalpage = petlist.size() / 5 + (petlist.size() % 5 == 0 ? 0 : 1);
		labpage.setText(nowpage + "/" + totalpage);
		// 展示的特效信息
		for (int i = 0; i < ((petlist.size() - (nowpage - 1) * 5) >= 5 ? 5 : (petlist.size() - (nowpage - 1) * 5)); i++) {
			part[i] = SpriteFactory.createPart(petlist.get(i + (nowpage - 1) * 5).getSummoningskin(), 2, 1, "");
			petName[i].setText(petlist.get(i + (nowpage - 1) * 5).getSummoningname());
			petnum[i].setText("碎片："+getPetdebrisNum(petlist.get(i + (nowpage - 1) * 5).getSummoningid()));
//			this.synthesis[i].setVisible(true);
			this.petdetails[i].setVisible(true);
//			this.synthesis[i].setText(petlist.get(i + (nowpage - 1) * 5).getId()+"");
			petids[i] = petlist.get(i + (nowpage - 1) * 5).getSummoningid()+"";

			if(nowpage == 1) {
				sxtp[i].setIcon(icon2);
				sxtp[i].setBounds(40+i*110, 70, 24, 43);
				this.sxtp[i].setVisible(true);
			}else {
				this.sxtp[i].setVisible(false);
			}
		}
	}



	public static JTextField getFindName() {
		return findName;
	}

	public static void setFindName(JTextField findName) {
		PetTujianJpanel.findName = findName;
	}

	public static JTextField getFindName1() {
		return findName1;
	}

	public static void setFindName1(JTextField findName1) {
		PetTujianJpanel.findName1 = findName1;
	}

	public String[] getFvalue() {
		return Fvalue;
	}

	public void setFvalue(String[] fvalue) {
		Fvalue = fvalue;
	}

	public JTextArea getTestMes() {
		return testMes;
	}

	public void setTestMes(JTextArea testMes) {
		this.testMes = testMes;
	}

	public JLabel getLabtext() {
		return labtext;
	}

	public void setLabtext(JLabel labtext) {
		this.labtext = labtext;
	}

	public JLabel getLabtext1() {
		return labtext1;
	}

	public void setLabtext1(JLabel labtext1) {
		this.labtext1 = labtext1;
	}

	public JLabel getLabtext2() {
		return labtext2;
	}

	public void setLabtext2(JLabel labtext2) {
		this.labtext2 = labtext2;
	}

	public JLabel getLabtext3() {
		return labtext3;
	}

	public void setLabtext3(JLabel labtext3) {
		this.labtext3 = labtext3;
	}

	public JLabel getLabtext4() {
		return labtext4;
	}

	public void setLabtext4(JLabel labtext4) {
		this.labtext4 = labtext4;
	}

	public JLabel getTgmText() {
		return tgmText;
	}

	public void setTgmText(JLabel tgmText) {
		this.tgmText = tgmText;
	}

	public WorkshopBtn getTuiguang() {
		return tuiguang;
	}

	public void setTuiguang(WorkshopBtn tuiguang) {
		this.tuiguang = tuiguang;
	}

	public WorkshopBtn getTuiguangSC() {
		return tuiguangSC;
	}

	public void setTuiguangSC(WorkshopBtn tuiguangSC) {
		this.tuiguangSC = tuiguangSC;
	}

	public String getNpczb() {
		return npczb;
	}

	public void setNpczb(String npczb) {
		this.npczb = npczb;
	}

	public static String getNpcfeiji() {
		return npcfeiji;
	}

	public static void setNpcfeiji(String npcfeiji) {
		PetTujianJpanel.npcfeiji = npcfeiji;
	}

	public ImageIcon getIcon() {
		return icon;
	}

	public void setIcon(ImageIcon icon) {
		this.icon = icon;
	}

	public ImageIcon getIcon1() {
		return icon1;
	}

	public void setIcon1(ImageIcon icon1) {
		this.icon1 = icon1;
	}
	public int getNowpage() {
		return nowpage;
	}

	public void setNowpage(int nowpage) {
		this.nowpage = nowpage;
	}
	public JLabel getLabpage() {
		return labpage;
	}

	public void setLabpage(JLabel labpage) {
		this.labpage = labpage;
	}

	public JLabel[] getPetnum() {
		return petnum;
	}


	public void setPetnum(JLabel[] petnum) {
		this.petnum = petnum;
	}


	public PetTujianSpecificBtn getSelectBtn() {
		return selectBtn;
	}


	public void setSelectBtn(PetTujianSpecificBtn selectBtn) {
		this.selectBtn = selectBtn;
	}


	public PetTujianSpecificBtn[] getSynthesis() {
		return synthesis;
	}


	public void setSynthesis(PetTujianSpecificBtn[] synthesis) {
		this.synthesis = synthesis;
	}


	public PetTujianSpecificBtn[] getPetdetails() {
		return petdetails;
	}


	public void setPetdetails(PetTujianSpecificBtn[] petdetails) {
		this.petdetails = petdetails;
	}


	public String[] getPetids() {
		return petids;
	}


	public void setPetids(String[] petids) {
		this.petids = petids;
	}


	//获取碎片数量
	public static String getPetdebrisNum(String petId) {
		String num = "0";
		return num;
	}


}
